<?php

/**
 * 
 * 发送邮件
 * @author alang
 *
 */

class Email_mdl extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();
	}
	
	
	/**
	 * 
	 * 发送邮件
	 * @param String $form
	 * @param Sting $to
	 * @param String $body
	 */
	public function sendEmail( $form,$to,$body )
	{
		
			$this->load->library('phpmailer');
			
			try {
				$this->phpmailer->IsSMTP();                           // tell the class to use SMTP
				$this->phpmailer->SMTPAuth   = true;                  // enable SMTP authentication
				$this->phpmailer->Port       = 25;                    // set the SMTP server port
				$this->phpmailer->Host       = "smtp.163.com"; // SMTP server
				$this->phpmailer->Username   = "lottery2013888@163.com";     // SMTP server username
				$this->phpmailer->Password   = "lottery2013";            // SMTP server password
			
				$this->phpmailer->IsSendmail();  // tell the class to use Sendmail
			
				$this->phpmailer->AddReplyTo($to,"First Last");
			
				$this->phpmailer->From       = "lottery2013888@163.com";
				$this->phpmailer->FromName   = "lottery";
	
				$this->phpmailer->AddAddress($to);
			
				$this->phpmailer->Subject  = "First PHPMailer Message";
			
				$this->phpmailer->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
				$this->phpmailer->WordWrap   = 80; // set word wrap
			
				$this->phpmailer->MsgHTML($body);
			
				$this->phpmailer->IsHTML(true); // send as HTML
			
				$this->phpmailer->Send();
				
				/*-------------------------*/
				$fp = fopen('email.txt','a+');
				fwrite($fp,$to.': '.date("Y-m-d H:i:s")."\r\n");
				fclose($fp);
				/*-------------------------*/
				return true;
			} catch ( phpmailerException $e ){
				/*-------------------------*/
				$fp = fopen('email.txt','a+');
				fwrite($fp,$to.': '.date("Y-m-d H:i:s").'-false' ."\r\n");
				fclose($fp);
				/*-------------------------*/
				return false;
				
			}
		

	}
	
}